package de.piratech.dasding.data.database.mongo.data;

import org.codehaus.jackson.annotate.JsonIgnore;

import net.vz.mongodb.jackson.ObjectId;
import de.piratech.dasding.data.AbstractDataObject;
import de.piratech.dasding.data.database.DataType;

public class AbstractMongoDataObject<T extends AbstractDataObject> {

  private T object;

  public AbstractMongoDataObject(T object) {
    this.object = object;
  }

  @ObjectId
  public String get_id() {
    return object.getId();
  }

  public void set_id(String pId) {
    object.setId(pId);
  }

  public DataType getDataType() {
    return object.getDataType();
  }

  public void setDataType(DataType pType) {
    object.setDataType(pType);
  }

  public int hashCode() {
    int hash = 5;
    hash = 67 * hash + (get_id() != null ? get_id().hashCode() : 0);
    return hash;
  }

  public boolean equals(Object pObj) {
    if (pObj == null) {
      return false;
    }
    if (getClass() != pObj.getClass()) {
      return false;
    }
    final AbstractMongoDataObject<?> other = (AbstractMongoDataObject<?>) pObj;
    if ((this.get_id() == null) ? (other.get_id() != null) : !this.get_id()
        .equals(other.get_id())) {
      return false;
    }
    return true;
  }

  @JsonIgnore
  public T getDataObject() {
    return this.object;
  }

}
